<?php
class UserDoLoginAction extends PiscesAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'json';
	}
	public function execute()
	{
		$this->code 	= 0;
		$password 		= trim($this->context->post('password'));
		$username 		= trim($this->context->post('username'));
		
		if($username!='' && $password!='')
		{
			$userService	= new UserService();
			$user			= $userService->checkUserLogin($username,$password);
			if($user)
			{
				$expire		= time() + 1200;
				$authCode 	= $user['id'] . "\t" . $user['username']. "\t" .$user['password']. "\t" .$expire;
				C("LtCookie")->setCookie('user_auth', $authCode, $expire);
				
				$this->code	= 200;
				$this->data['forward'] = C('LtUrl')->generate('User', 'HasLogin');
			}
		}
	}
}